package com.gxitsky.config;

import com.gxitsky.service.HelloService;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * @author gxing
 * @desc Web Service Config
 * @date 2021/2/26
 */
@Configuration
public class WebServiceConfig {

    @Autowired
    private HelloService helloService;

    /**
     * 自定义 Spring Bus, 可省略, 自动配置已注册
     * @return SpringBus
     */
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    /**
     * 自定义CXF Servlet,设置前缀, 默认是 /services,
     * 可省略,直接在 application.properties中设置 cxf.path=/services
     * @return ServletRegistrationBean
     */
/*    @Bean
    public ServletRegistrationBean<Servlet> dispatcherServlet() {
        return new ServletRegistrationBean<>(new CXFServlet(), "/soap/*");
    }*/

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), helloService);
        endpoint.publish("/ws/hello");
        return endpoint;
    }
}
